/***
    Amrita ITEWS - Copyright (C) 2009 Amrita Vishwa Vidyapeetham, Amritapuri.
                                       (http://www.amrita.edu)
    ***************************************************************************
    This file is part of the Amrita ITEWS distribution.
    Amrita ITEWS is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License (version 2) as published
    by the Free Software Foundation AND MODIFIED BY the Amrita ITEWS exception.
    ***NOTE*** The exception to the GPL is included to allow you to distribute
    a combined work that includes Amrita ITEWS without being obliged to provide
    the source code for proprietary components outside of the Amrita ITEWS
    software. Amrita ITEWS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    Public License for more details. You should have received a copy of the GNU
    General Public License and the Amrita ITEWS license exception along with
    Amrita ITEWS if not then it can be viewed here:
    http://itews.amrita.ac.in/license.html.


    Documentation, latest information, license and contact details are at:
    http://itews.amrita.ac.in/


    Amrita ITEWS source code can be found at:
    http://code.google.com/p/itews


    The initial code-base of Amrita ITEWS was developed by Amrita Vishwa
    Vidyapeetham as part of the project titled,"Intelligent & Interactive
    Telematics using Emerging Wireless Technologies for Transport Systems
    (ITEWS)" sponsored by Technology Information Forecasting and Assessment
    Council (TIFAC), India.
***/
/*! \file serial_eventq.h
    \brief Serial Event Queue Header File.
    */

#ifndef SERIAL_EVENTQ_H_
#define SERIAL_EVENTQ_H_
#include <eventq.h>


/*! \brief Open Serial Port Event Type Flag
  PUT event,
  param (I) - address of serial_param_t which contains the following -
     baudrate (SERIAL_BAUD_xxx),
     bitcnt (SERIAL_BIT_xx),
     parity ,
     comport (SERIAL_COMx),
     mode - SERIAL_MODE_xxx,
     mode_param - For SERIAL_MODE_DLE - the DLE character is given,
  buf - none.
 */
#define     EVT_SERIAL_OPEN             0x00

/*! \brief Serial Send Data Event Type Flag
 * PUT event,
  param - none
  buf (I) - data to be send.
  */
#define     EVT_SERIAL_PUT_DATA         0x01

/*! \brief Serial Receive Data Event Type Flag
 GET event,
 param - none
  buf (O) - buffer to which data has to be read
  (must be allocated by the caller).
  (return nbytes read.)
  */
#define     EVT_SERIAL_GET_DATA         0x02

/*! \brief Serial Timed Data Receive Event Type Flag
 param (I)- timeout delay in milli seconds.
 param (O)- status (SERIAL_READ_TIMEOUT/SERIAL_DLE_RECEIVED).
 buf (O) - buffer to which data has to be read
  (must be allocated by the caller).
  (return nbytes read.)
 */
#define     EVT_SERIAL_TIMED_GET_DATA   0x03

/*! \brief Serial Device Odd Parity Flag.*/
#define     SERIAL_PARITY_ODD           'O'

/*! \brief Serial Device Even Parity Flag.*/
#define     SERIAL_PARITY_EVEN          'E'

/*! \brief Serial Device No Parity Flag.*/
#define     SERIAL_NO_PARITY            'N'

/*! \brief Serial Device in Synchronous Mode.*/
#define     SERIAL_SYNC_MODE            'S'

/*! \brief Serial Device in Asynchronous Mode.*/
#define     SERIAL_ASYNC_MODE           'A'

/*! \brief Serial COM Port 1 (ttyS0).*/
#define     SERIAL_COM1                 0

/*! \brief Serial COM Port 2 (ttyS1).*/
#define     SERIAL_COM2                 1

/*! \brief Serial COM Port 3 (ttyS2).*/
#define     SERIAL_COM3                 2

/*! \brief Serial COM Port 4 (ttyS3).*/
#define     SERIAL_COM4                 3

/*! \brief Baud rate 115200 for Serial Communication.*/
#define     SERIAL_BAUD_115200          115200

/*! \brief Baud rate 57600 for Serial Communication.*/
#define     SERIAL_BAUD_57600           57600

/*! \brief Baud rate 38400 for Serial Communication.*/
#define     SERIAL_BAUD_38400           38400

/*! \brief Baud rate 19200 for Serial Communication.*/
#define     SERIAL_BAUD_19200           19200

/*! \brief Baud rate 9600 for Serial Communication.*/
#define     SERIAL_BAUD_9600            9600

/*! \brief Bit Count for GPRS Serial Communication.*/
#define     SERIAL_BITCNT_8             8

/*! \brief Serial Read Timeout status Flag.*/
#define     SERIAL_READ_TIMEOUT         1

/*! \brief Serial DLE Escape Received Modem status Flag.*/
#define     SERIAL_DLE_RECVD            2

/*! \brief DLE mode enable, the DLE character must be provided
 in mode_param field during SERIAL_OPEN.
 */
#define     SERIAL_MODE_DLE             1

/*! \brief Event Queue Operation Structure Global Variable.*/
extern eventq_ops_t serial_eventq_ops;

/*! \brief Serial Event Data Structure.*/
typedef struct
{
    /*! \brief Parity Flag for serial communication (odd/even/noparity). */
    int8 parity;

    /*! \brief Mode of Operation (Sync/Async). */
    int8 mode;

    /*! \brief Mode parameter. */
    uint32 mode_param;

    /*! \brief Number of data bits in serial communication (5-8). */
    uint8 bits;

    /*! \brief Serial Port SERIAL_PORT_xx. */
    uint8 port;

    /*! \brief Baud rate for serial communication. */
    int32 baud;

    /*! \brief Hardware FlowControl Enable Flag.*/
    uint8 flow_control_enable;

}serial_param_t;


/*SPI*/
STATUS serial_eventq_open       ( eventq_ctx_t *, const char *eventq_name );
STATUS serial_eventq_close      ( eventq_ctx_t * );
STATUS serial_eventq_sync_put   ( eventq_ctx_t *, event_t *, HRESULT *res );
STATUS serial_eventq_sync_get   ( eventq_ctx_t *, event_t * );

#endif /*SERIAL_EVENTQ_H_*/

